home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
NetNews Offline 2
/
NetNews Offline Volume 2.iso
/
news
/
comp
/
std
/
c
/
123
< prev
next >
Wrap
Text File
|
1996-08-06
|
2KB
|
68 lines
Newsgroups: comp.std.c
Path: blackbush.xlink.net!slsv6bt!slsv6bt!kanze
From: kanze@lts.sel.alcatel.de (James Kanze US/ESC 60/3/141 #40763)
Subject: Re: ... char * * promotion to char const * const * ...
In-Reply-To: mklenk@updike.sri.com's message of 16 Jan 1996 16:20:42 GMT
Message-ID: <KANZE.96Jan17121659@slsvewt.lts.sel.alcatel.de>
Sender: news@lts.sel.alcatel.de
Organization: SEL
References: <4dgj8q$qin@unix.sri.com>
Date: 17 Jan 1996 11:16:57 GMT
In article <4dgj8q$qin@unix.sri.com> mklenk@updike.sri.com (Mark
Klenk) writes:
|> My question is this:
|> Why does a char * * not naturally promote to a
|> char const * const *?
Because the C standard forbids it.
|> The following is legal and generates no compiler
|> warning:
|> char const * foo;
|> char * bar;
|> foo = bar;
|> // bar = foo; // Not allowed without cast.
|> But why not this:
|> char const * const * foo_array;
|> char * * bar_array;
|> foo_array = bar_array;
|> On every compiler I've tried, I get a warning about this,
|> something like "assignment from incompatible pointer type."
As I understand it:
Originally, the C standard was going to allow this; in fact, it was
going to allow all casts which added const anywhere in the type. Then
someone pointed out that the conversion 'char ** -> char *const *' was
unsafe. As a result, the wording was changed to only allow adding the
const at the top level.
During the C++ standardization efforts (much later), Andy Koenig
pointed out that this rule in fact excluded a number of safe casts as
well, and proposed changing it for C++. A new rule was formulated,
and one of the committee members actually did a mathematical proof
that it allowed all safe casts, and excluded all unsafe ones. (If
memory serves me right, the rule is not the same for const and for
volatile.)
Since the C standardization committee is currently considering a new
version of the standard, perhaps they will also consider adapting the
C++ rules for this case. (Since it results in a loosening of the
restrictions, no conforming program can be affected.)
--
James Kanze Tel.: (+33) 88 14 49 00 email: kanze@gabi-soft.fr
GABI Software, Sarl., 8 rue des Francs-Bourgeois, F-67000 Strasbourg, France
Conseils, Θtudes et rΘalisations en logiciel orientΘ objet --
-- A la recherche d'une activitΘ dans une region francophone